package com.tr.rentcar.controller.houtai.statistics;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.tr.rentcar.model.bean.CarBrand;
import com.tr.rentcar.model.dao.CarBrandDao;
import com.tr.rentcar.model.dao.OrderDao;

/**
 * Servlet 
 */
@WebServlet("/sales")
public class SalesTjController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.getRequestDispatcher("/WEB-INF/jsp/houtai_sales.jsp").forward(request, response);
		
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		CarBrandDao cbd=new CarBrandDao();
		OrderDao od=new OrderDao();
		Map map=new HashMap();
		try {
			List<CarBrand> listcb=cbd.getAll();
			for (CarBrand carBrand : listcb) {
				long num=od.getBrandCount(carBrand.getCbName());
				map.put(carBrand.getCbName(), num);
			}
			out.print(JSONArray.toJSONString(map));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
